<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
     const url = 'https://www.imooc.com/api/http/search/suggest?words=js';
    //fetch()调用后返回promise对象
    /*body: (...)
    bodyUsed: false
    headers: Headers {}
    ok: true
    redirected: false
    status: 200
    statusText: "OK"
    type: "cors"
    url: "https://www.imooc.com/api/http/search/suggest?words=js"
    __proto__: Response */

    console.log(fetch);
    const fd=new FormData();
    fd.append('usernam','b')
    //第二个参数是对象
    fetch(url,{method:'post',body:JSON.stringify({name:'a'}),headers:{'Content-Type':'application/json'},mode:'cors}',credentials:'include'}).then(response=>{
      console.log(response);
      //body/bodyUsed body只能读一次，读过之后就不让再读了
      //ok如果为true，表示可以读取数据，不用再去判断http状态码了
      if(response.ok){
        // console.log(response.json());
        // return response.json()
        return response.text()
        
      }
    }).then(data=>{
      console.log(data);
    })
  </script>
</body>
</html>